package com.qf.studentmanager.service;

import com.qf.studentmanager.dao.CourseDao;
import com.qf.studentmanager.dao.UserDao;
import com.qf.studentmanager.model.Course;
import com.qf.studentmanager.model.User;


import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class UserService {
   UserDao userDao = new UserDao();

    public Integer login(HttpServletRequest request,String username, String password) {
        User user =userDao.getUserByUsername(username);
        if(user == null){  //用户名错
            return -1;
        }else { //用户名对，再往下判断
            if (!password.equals(user.getPassword())){
                return -1;
            }else if (!user.getEnabled()){
                return -2;
            }
        }
        request.getSession().setAttribute("loginUser", user);
        return 1;

    }

    public List<Course> getCourses() {
        CourseDao courseDao = new CourseDao();
        return  courseDao.getCourses();
    }
}
